import os


f_name = 'file_test.txt'
f_new_name = "%s.new"%f_name

old_str = "test"
new_str = "路飞学院"


f = open(f_name,'r',encoding='utf-8')
f_new = open(f_new_name,'w',encoding="utf-8")

for line in f:
    if old_str in line:
        line = line.replace(old_str,new_str)
    f_new.write(line)

f.close()
f_new.close()

os.rename(f_new_name,f_name)